package com.pudu.mydemo.act;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;

import com.pudu.mydemo.view.AnimTextView;
import com.pudu.mydemo.view.MagicProgressCircle;
import com.pudutech.pdrobot.R;

/**
 * Created by guiliu on 2016/7/15.
 */
public class ShutDownActivity extends BaseHomeActivity {
    private AnimTextView demoTv;
    private boolean isAnimActive;
    private ImageView ok, cancel;
    private MagicProgressCircle demoMpc;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_shutdown;
    }

    @Override
    public void initView() {
        ok = (ImageView)findViewById(R.id.ok);
        cancel = (ImageView)findViewById(R.id.cancel);
        demoMpc = (MagicProgressCircle) findViewById(R.id.demo_mpc);
        demoTv = (AnimTextView)findViewById(R.id.demo_tv);
        final AnimatorSet set = new AnimatorSet();
        set.playTogether(
              ObjectAnimator.ofFloat(demoMpc, "percent", 0, 100 / 100f),
                ObjectAnimator.ofInt(demoTv, "progress",9, 0)
                /*    ObjectAnimator.ofFloat(demo1Mpb, "percent", 0, random.nextInt(ceil) / 100f),
                    ObjectAnimator.ofFloat(demo2Mpb, "percent", 0, random.nextInt(ceil) / 100f),
                    ObjectAnimator.ofFloat(demo3Mpb, "percent", 0, random.nextInt(ceil) / 100f),
                    ObjectAnimator.ofFloat(demo4Mpb, "percent", 0, random.nextInt(ceil) / 100f)*/
        );
        set.setDuration(9000);
        set.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                isAnimActive = true;
            }

            @Override
            public void onAnimationEnd(Animator animation) {

                isAnimActive = false;
                finish();

            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        set.setInterpolator(new AccelerateInterpolator());
        set.start();

        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShutDownActivity.this.finish();
            }
        });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ShutDownActivity.this, SmailActivity.class);
                set.pause();
                isAnimActive = false;
                startActivity(intent);
            }
        });
    }


   /* @Override
    public void initEvent() {
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            ShutDownActivity.this.finish();
            }
        });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ShutDownActivity.this, SmailActivity.class);
                startActivity(intent);
            }
        });
    }*/
}
